package com.ccit.area.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccit.area.service.AreaService;
import com.ccit.model.Area;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api/area")
public class AreaApiController {
    @Autowired
    private AreaService areaService;

    //根据id查询场地信息
    @ApiOperation("根据Id查询场地")
    @GetMapping("/getById/{areaId}")
    public Area getById(
            @ApiParam(value = "场地id",required = true)
            @PathVariable Long areaId){
        Area area = areaService.getById(areaId);
        return area;
    }

    //根据名字查询场地信息
    @ApiOperation("根据名称查询场地")
    @GetMapping("/getByName/{areaName}")
    public Area getByName(
            @ApiParam(value = "场地名称",required = true)
            @PathVariable String  areaName){
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(Area::getName,areaName);
        Area area = areaService.getOne(wrapper);
        return area;
    }
}
